package org.nnxy.foodboot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.nnxy.foodboot.entity.UserFeature;
import org.nnxy.foodboot.mapper.UserFeatureMapper;
import org.nnxy.foodboot.service.UserFeatureService;
import org.springframework.stereotype.Service;

/**
 * 用户特征Service实现类
 */
@Service
@RequiredArgsConstructor
public class UserFeatureServiceImpl extends ServiceImpl<UserFeatureMapper, UserFeature> implements UserFeatureService {
    
    @Override
    public UserFeature getUserFeatureByUserId(Integer userId) {
        if (userId == null) {
            return null;
        }
        
        LambdaQueryWrapper<UserFeature> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserFeature::getUserId, userId);
        
        return getOne(queryWrapper);
    }
    
    @Override
    public boolean saveOrUpdateUserFeature(UserFeature userFeature) {
        if (userFeature == null || userFeature.getUserId() == null) {
            return false;
        }
        
        UserFeature existingFeature = getUserFeatureByUserId(userFeature.getUserId());
        
        if (existingFeature != null) {
            userFeature.setId(existingFeature.getId());
            return updateById(userFeature);
        } else {
            return save(userFeature);
        }
    }
} 